﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.LocalKeyword
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>Represents a shader keyword declared in a shader source file.</para>
  /// </summary>
  [NativeHeader("Runtime/Shaders/Keywords/KeywordSpaceScriptBindings.h")]
  [NativeHeader("Runtime/Graphics/ShaderScriptBindings.h")]
  [UsedByNativeCode]
  public readonly struct LocalKeyword : IEquatable<LocalKeyword>
  {
    internal readonly LocalKeywordSpace m_SpaceInfo;
    internal readonly string m_Name;
    internal readonly uint m_Index;

    [FreeFunction("keywords::IsKeywordOverridable")]
    private static bool IsOverridable(LocalKeyword kw)
    {
      return LocalKeyword.IsOverridable_Injected(ref kw);
    }

    [FreeFunction("ShaderScripting::GetKeywordCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetShaderKeywordCount(Shader shader);

    [FreeFunction("ShaderScripting::GetKeywordIndex")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetShaderKeywordIndex(Shader shader, string keyword);

    [FreeFunction("ShaderScripting::GetKeywordCount")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetComputeShaderKeywordCount(ComputeShader shader);

    [FreeFunction("ShaderScripting::GetKeywordIndex")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern uint GetComputeShaderKeywordIndex(ComputeShader shader, string keyword);

    [FreeFunction("keywords::GetKeywordType")]
    private static ShaderKeywordType GetKeywordType(LocalKeywordSpace spaceInfo, uint keyword)
    {
      return LocalKeyword.GetKeywordType_Injected(ref spaceInfo, keyword);
    }

    [FreeFunction("keywords::IsKeywordValid")]
    private static bool IsValid(LocalKeywordSpace spaceInfo, uint keyword)
    {
      return LocalKeyword.IsValid_Injected(ref spaceInfo, keyword);
    }

    /// <summary>
    ///   <para>The name of the shader keyword (Read Only).</para>
    /// </summary>
    public string name => this.m_Name;

    /// <summary>
    ///   <para>Whether this shader keyword was declared with global scope. (Read Only).</para>
    /// </summary>
    public bool isOverridable => LocalKeyword.IsOverridable(this);

    /// <summary>
    ///   <para>Specifies whether this local shader keyword is valid (Read Only).</para>
    /// </summary>
    public bool isValid => LocalKeyword.IsValid(this.m_SpaceInfo, this.m_Index);

    /// <summary>
    ///   <para>The type of the shader keyword (Read Only).</para>
    /// </summary>
    public ShaderKeywordType type => LocalKeyword.GetKeywordType(this.m_SpaceInfo, this.m_Index);

    /// <summary>
    ///   <para>Initializes and returns a LocalKeyword struct that represents an existing local shader keyword for a given Shader.</para>
    /// </summary>
    /// <param name="shader">The Shader to use.</param>
    /// <param name="name">The name of the local shader keyword.</param>
    public LocalKeyword(Shader shader, string name)
    {
      if ((UnityEngine.Object) shader == (UnityEngine.Object) null)
        Debug.LogError((object) "Cannot initialize a LocalKeyword with a null Shader.");
      this.m_SpaceInfo = shader.keywordSpace;
      this.m_Name = name;
      this.m_Index = LocalKeyword.GetShaderKeywordIndex(shader, name);
      if (this.m_Index < LocalKeyword.GetShaderKeywordCount(shader))
        return;
      Debug.LogErrorFormat("Local keyword {0} doesn't exist in the shader.", (object) name);
    }

    /// <summary>
    ///   <para>Initializes and returns a LocalKeyword struct that represents an existing local shader keyword for a given ComputeShader.</para>
    /// </summary>
    /// <param name="shader">The ComputeShader to use.</param>
    /// <param name="name">The name of the local shader keyword.</param>
    public LocalKeyword(ComputeShader shader, string name)
    {
      if ((UnityEngine.Object) shader == (UnityEngine.Object) null)
        Debug.LogError((object) "Cannot initialize a LocalKeyword with a null ComputeShader.");
      this.m_SpaceInfo = shader.keywordSpace;
      this.m_Name = name;
      this.m_Index = LocalKeyword.GetComputeShaderKeywordIndex(shader, name);
      if (this.m_Index < LocalKeyword.GetComputeShaderKeywordCount(shader))
        return;
      Debug.LogErrorFormat("Local keyword {0} doesn't exist in the compute shader.", (object) name);
    }

    public override string ToString() => this.m_Name;

    public override bool Equals(object o) => o is LocalKeyword rhs && this.Equals(rhs);

    public bool Equals(LocalKeyword rhs)
    {
      return this.m_SpaceInfo == rhs.m_SpaceInfo && (int) this.m_Index == (int) rhs.m_Index;
    }

    public static bool operator ==(LocalKeyword lhs, LocalKeyword rhs) => lhs.Equals(rhs);

    public static bool operator !=(LocalKeyword lhs, LocalKeyword rhs) => !(lhs == rhs);

    public override int GetHashCode()
    {
      return this.m_Index.GetHashCode() ^ this.m_SpaceInfo.GetHashCode();
    }

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsOverridable_Injected(ref LocalKeyword kw);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern ShaderKeywordType GetKeywordType_Injected(
      ref LocalKeywordSpace spaceInfo,
      uint keyword);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsValid_Injected(ref LocalKeywordSpace spaceInfo, uint keyword);
  }
}
